<template>
  <div>
    <van-nav-bar
        title="设置"
        fixed
        left-arrow
        @click-left="goBack()"
    />
    <div style="padding: 8vh 0 0 0">

      <p style="margin: 1vh 3vh; color: grey ">个人资料</p>
      <van-cell-group inset>
        <van-cell title="编辑资料" is-link to="userUpdate"/>
        <van-cell title="修改密码" is-link to="passwordUpdate"/>
      </van-cell-group>

      <p style="margin: 1vh 3vh; color: grey ">其他</p>
      <van-cell-group inset>
        <van-cell v-if="user.isAdmin" title="管理后台" @click="goAdmin"/>
        <van-cell title="退出登录" @click="logout"/>
      </van-cell-group>

    </div>

  </div>
</template>

<script>
import { mapMutations } from "vuex";

export default {
  data() {
    return {
      user:{
        isAdmin:""
      }
    }
  },
  methods: {
    ...mapMutations(["removeToken"]),
    goAdmin() {
      this.$router.push("/admin");
    },
    goBack() {
      this.$router.go(-1);
    },
    logout() {
      this.http.get("/api/phx/user/logout").then(() => {
        this.removeToken();
        this.$router.push("/login");
      });
    },
    userDetail() {
      this.http.get("/api/phx/user/detail?userId=").then((res) => {
        this.user.isAdmin = res.data.data.isAdmin;
      });
    }
  },
  mounted() {
    this.userDetail();
  }
}
</script>

<style scoped>

</style>